package drexel.cs544.nap;

//package drexel.cs544.nap;

import drexel.cs544.nap.client.NAPClient;
import drexel.cs544.nap.log.LoggerSetup;
import drexel.cs544.nap.server.NAPServer;
import java.io.File;
import java.net.InetAddress;
import org.apache.log4j.Logger;


/**
 *
 * @author rch_ltp
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) { 
        if (args.length < 1 || args.length > 2)
        {
            System.out.println("Please provide switches, -client SERVER_NAME or" +
                    " -server, to launch in proper context.");
            System.exit(-1);
        }

        try
        {
            if (args[0].equalsIgnoreCase("-client"))
            {
                //Launch client
                String serverName = (args.length == 2) ? args[1] :
                    InetAddress.getLocalHost().getHostName();
                LoggerSetup.init(new File("log", "NAPClient.log"));
                Logger.getLogger(Main.class).info("Loading client protocol...");
                NAPClient.getInstance().connect(serverName);
            }
            else if (args[0].equalsIgnoreCase("-server"))
            {
                //Launch server
                LoggerSetup.init(new File("log", "NAPServer.log"));
                Logger.getLogger(Main.class).info("Loading server protocol...");
                NAPServer.getInstance().start();
            }
            else
                System.out.println("An unknown switch, " + args[0]
                        + ", was provided.");
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            System.exit(-1);
        }
    }

}
